<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="common/include :: header('养修服务单项列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                            关键字查询：<input type="text" name="nameOrEmail"/>
                        </li>
                        <li>
                            所在部门：
                            <select name="departmentId" th:with="type=${@dept.list()}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.name}"
                                        th:value="${dict.id}"></option>
                            </select>
                        </li>
                        <li>
                            是否超级管理员：
                            <select name="isAdmin" th:with="type=${@dict.getType('sys_user_admin')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.label}"
                                        th:value="${dict.value}"></option>
                            </select>
                        </li>
                        <li>
                            是否冻结：
                            <select name="isFreeze" th:with="type=${@dict.getType('sys_is_freeze')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.label}"
                                        th:value="${dict.value}"></option>
                            </select>
                        </li>
                        <li class="select-time">
                            <label>入职时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="beginTime"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="endTime"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="business:service:add">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary auditBtn" onclick="startAudit()"
               shiro:hasPermission="business:service:edit">
                <i class="fa fa-edit"></i> 发起审批
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="common/include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('business:employee:edit')}]];
    var saleOnFlag = [[${@permission.hasPermi('business:employee:saleOn')}]];
    var saleOffFlag = [[${@permission.hasPermi('business:employee:saleOff')}]];
    var carPackageDatas = [[${@dict.getType('si_car_package')}]];
    var serviceCatalogDatas = [[${@dict.getType('si_service_catalog')}]];
    var auditStatusDatas = [[${@dict.getType('si_audit_status')}]];
    var saleStatusDatas = [[${@dict.getType('si_sale_status')}]];
    var prefix = ctx + "/business/employee";
    $(function () {
        var options = {
            url: prefix + "/query",
            createUrl: prefix + "/addPage",
            updateUrl: prefix + "/editPage?id={id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "员工",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '服务id',
                    visible: false
                },
                {
                    field: 'name',
                    title: '姓名',

                },
                {
                    field: 'email',
                    title: '邮箱',

                },
                {
                    field: 'age',
                    title: '年龄',

                },
                {
                    field: 'admin',
                    title: '是否管理员',
                    formatter: function (value, item, index) {
                        if (value == '1') {
                            return '<span class="label label-success">是</span>';
                        } else if (value == '0') {
                            return '<span class="label label-primary">否</span>';
                        }
                    }

                },
                {
                    field: 'hiredate',
                    title: '入职时间',

                },
                {
                    field: 'deptName',
                    title: '所在部门',

                },
                {
                    field: 'deptId',
                    title: '部门id',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        var editBtnFlag = editFlag;
                        var saleOffBtnFlag = saleOffFlag;
                        var saleOnBtnFlag = saleOnFlag;
                        actions.push('<a class="btn btn-success btn-xs ' + '' + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')">' +
                            '<i class="fa fa-edit"></i>编辑</a> ');

                        actions.push('<a class="btn btn-warning btn-xs ' + saleOffBtnFlag + '" href="javascript:void(0)" onclick="detail(\'' + row.deptId + '\')"><i class="fa fa-edit"></i>查看部门详情</a>');
                        actions.push('<a class="btn btn-danger btn-xs ' + '' + '"  href="javascript:void(0)" onclick="deleteFun(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

        $("#bootstrap-table").on("check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table load-success.bs.table", function () {
            //下架才能进行修改
            var rows = $.table.selectColumns("carPackage");
            if (rows.length == 1 && rows[0] == 1) {
                //是套餐且状态为初始化或者拒绝
                var auditStatus = $.table.selectColumns("auditStatus")[0];
                console.log(auditStatus == 0);
                if (auditStatus == 0 || auditStatus == 3) {
                    $(".auditBtn").removeClass("disabled");
                    return;
                }
            }
            $(".auditBtn").addClass("disabled");
        });
    });

    function saleOff(id) {
        $.modal.confirm("确认需要下架此服务项吗?", function () {
            $.operate.submit(prefix + "/saleOff?id=" + id, "post");
        });
    }

    function saleOn(id) {
        $.modal.confirm("确认需要上架此服务项吗?", function () {
            $.operate.submit(prefix + "/saleOn?id=" + id, "post");
        });

    }

    function startAudit() {
        // 获取我勾选的数据条数，获取id这个值
        var rows = $.table.selectColumns("id");
        // 获取该集合第一个数据，也就是第一个id，打开模态框
        $.modal.open("发起审核", prefix + "/auditPage?id=" + rows[0]);
    }

    function deleteFun(id) {
        $.modal.confirm("确定要删除吗", function () {
            $.operate.post(ctx + "/business/employee/remove?ids=" + id, function (result) {
                $.operate.ajaxSuccess(result);
            });
        });
    }

    function detail(deptId) {
        var url = ctx + '/business/employee/selectDept?deptId=' + deptId;
        $.modal.open("部门查看", url);
    }
</script>
</body>
</html> 